package com.deviche.taoke.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Toast;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.deviche.taoke.GoodsPaser;
import com.deviche.taoke.R;
import com.deviche.taoke.base.BaseFragment;
import com.deviche.taoke.bean.Goods;
import com.deviche.taoke.common.Constant;
import com.deviche.taoke.ui.activity.GoodsDetailActivity;
import com.deviche.taoke.ui.adapter.CommonAdapter;

import java.util.ArrayList;

/**
 * Created by h on 2018/4/20.
 */

public class DataFragment extends BaseFragment {
    //大数据页面
    private RecyclerView mRecyclerView;
    private ArrayList<Goods> datas;
    private CommonAdapter adapter;
    public static final String TAG = DataFragment.class.getSimpleName();
    //private SwipeRefreshLayout mSwipeRefreshLayout;
    @Override
    protected int getLayoutId() {
        return R.layout.fragment_data;
    }

    @Override
    protected void initView(View view, Bundle savedInstanceState) {
        mRecyclerView = view.findViewById(R.id.rv_data);
        mRecyclerView.setLayoutManager(new GridLayoutManager(mContext,2));
        datas = new ArrayList<>();
        new Thread(new Runnable() {
            @Override
            public void run() {
                datas = GoodsPaser.parseFrom(Constant.HOST);
            }
        }).start();

        //创建适配器
        adapter = new CommonAdapter(R.layout.item_rv, datas);
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Intent intent = new Intent();
                intent.setClass(mContext,GoodsDetailActivity.class);
                startActivity(intent);
                Toast.makeText(mContext, "onItemClick" + position, Toast.LENGTH_SHORT).show();
            }
        });
        //给RecyclerView设置适配器
        mRecyclerView.setAdapter(adapter);
    }

    @Override
    protected void initData() {

    }
}
